var { App } = require("../../base/index");
var {
  randomUtils,
  clickUtils,
  logUtils,
  clickContent,
} = require("../../utils/index");
var aRead = require("./aRead");
var aTreasure = require("./aTreasure");
var common = require("./common");
var pointMap = require("./pointMap");

var kuaiShouJiSu = new App("快手极速版", {
  interval: 10 * 60,
  maxRunTCount: 3,
});
kuaiShouJiSu.runTest = function (count) {
  logUtils.info("runTest", count, "/", this.maxRunTCount);
  if (count == 0) {
    sleep(randomUtils.getRandom(2.5, 5, 1000));
    return;
  }
  if (count == 1) {
    clickUtils.clickPointMap(pointMap.首页.去赚钱);
    sleep(randomUtils.getRandom(8, 10, 1000));
    this.firstInTask();
    return;
  }
  if (count == 2) {
    clickUtils.clickPointMap(pointMap.首页.去赚钱);
    sleep(randomUtils.getRandom(8, 10, 1000));
    this.firstInTask();
    return;
  }
};
kuaiShouJiSu.firstInTask = function () {
  var content = "立即签到";
  if (clickContent(content)) {
    sleep(randomUtils.getRandom(2, 5, 1000));
    return;
  }
  var content = "立即领取";
  if (clickContent(content)) {
    sleep(randomUtils.getRandom(2, 5, 1000));
    return;
  }
  var content = "点就领";
  if (clickContent(content)) {
    sleep(randomUtils.getRandom(2, 5, 1000));
    if (randomUtils.possible(90, 100)) {
      clickUtils.clickPointMap(pointMap.任务.点就领.关闭);
      sleep(randomUtils.getRandom(2, 5, 1000));
    }
    return;
  }
};
kuaiShouJiSu.run = function () {
  aRead.flow();
  if (common.inHome()) {
    this.randomInHome(0);
    clickUtils.clickPointMap(pointMap.首页.去赚钱);
    sleep(randomUtils.getRandom(8, 12, 1000));
    aTreasure.flow();
    this.randomInHome(1);
  }
};
kuaiShouJiSu.randomInHome = function (type) {
  if (randomUtils.possible(80, 100)) {
    clickUtils.clickPointMap(pointMap.首页.朋友);
    sleep(randomUtils.getRandom(2, 10, 1000));
  }
  if (randomUtils.possible(90, 100)) {
    clickUtils.clickPointMap(pointMap.首页.我);
    sleep(randomUtils.getRandom(2, 10, 1000));
    if (randomUtils.possible(90, 100)) {
      var content = "常访问的人";
      if (clickContent(content)) {
        sleep(randomUtils.getRandom(2, 10, 1000));
        back();
        sleep(randomUtils.getRandom(2, 10, 1000));
      }
    }
  }
};

module.exports = kuaiShouJiSu;
